home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / WindowMaker / src / DL.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-20  |  6.2 KB  |  228 lines

  1. /*
  2.  * DL.h -  support for logging (printf...) style debugging using gdb.
  3.  *
  4.  * Copyright (c) 1997 Phil Maker
  5.  * All rights reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  * 1. Redistributions of source code must retain the above copyright
  11.  *    notice, this list of conditions and the following disclaimer.
  12.  * 2. Redistributions in binary form must reproduce the above copyright
  13.  *    notice, this list of conditions and the following disclaimer in the
  14.  *    documentation and/or other materials provided with the distribution.
  15.  *
  16.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  17.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  20.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  22.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  23.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  24.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  25.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  26.  * SUCH DAMAGE.
  27.  *
  28.  * Id: DL.h,v 1.1.1.1 1997/11/23 11:45:50 pjm Exp 
  29.  */
  30.  
  31. #ifndef _DL_h_
  32. #define _DL_h_ 1
  33.  
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37.  
  38. #ifndef WITHOUT_NANA 
  39.  
  40. /*
  41.  * nana-config.h - the system wide configuration file; we put the ifndef
  42.  *   around it to avoid the file 5 million times during a compile.
  43.  */
  44.  
  45. #ifndef _nana_config_h_
  46. #include <nana-config.h>
  47. #endif
  48.  
  49. /*
  50.  * DL_MAKE_VALID_BREAKPOINT() - used to make sure that we can put a
  51.  *   breakpoint at this location. We default to a portable C expression
  52.  *   which simply does an assignment. The configure script may override
  53.  *   this (on an architecture basis) and replace it with something
  54.  *   like asm("nop");
  55.  */
  56.  
  57. #ifndef DL_MAKE_VALID_BREAKPOINT
  58. static volatile int _dl_target;
  59.  
  60. #define DL_MAKE_VALID_BREAKPOINT() _dl_target = 0
  61. #endif
  62.  
  63. /* 
  64.  * DL_LEVEL sets the level of logging analogously to NDEBUG in assert.h
  65.  *
  66.  *   DL_LEVEL == 2: always print.
  67.  *   DL_LEVEL == 1: print iff the guard is true.
  68.  *   DL_LEVEL == 0: never print.
  69.  */
  70.  
  71. #ifndef DL_LEVEL /* define DEFAULT for DL_LEVEL */
  72. #define DL_LEVEL 1
  73. #endif
  74.  
  75. /* 
  76.  * DL_DEFAULT_HANDLER - the default print handler; by default we just
  77.  *   the debugger printf.
  78.  *
  79.  * @@call (void) printf(f)@@
  80.  */
  81.  
  82. #ifndef DL_DEFAULT_HANDLER /* define default handler */
  83. #define DL_DEFAULT_HANDLER(g,h,p,f...) @@printf f@@
  84. #endif /* DL_DEFAULT_HANDLER */
  85.  
  86. /*
  87.  * DL_DEFAULT_GUARD - the default guard expression; a message is printed
  88.  *     iff the guard is true. By default its always true.
  89.  */
  90.  
  91. #ifndef DL_DEFAULT_GUARD
  92. #define DL_DEFAULT_GUARD (1)
  93. #endif
  94.  
  95. /*
  96.  * DL_DEFAULT_PARAMS - the default value to be passed as the second argument
  97.  *       to the handler macro when an invariant fails.
  98.  */
  99.  
  100.  
  101. #ifndef DL_DEFAULT_PARAMS
  102. #define DL_DEFAULT_PARAMS stderr
  103. #endif
  104.  
  105. /*
  106.  * DL_SHOW_TIME - if its defined then each message gets a timestamp in front.
  107.  */
  108.  
  109. #ifdef DL_SHOW_TIME
  110.  
  111. unsigned long _L_gettime(void); /* returns the current time */
  112.  
  113. #define _DL_SHOWTIME(h,p) @@call (void) h (p, "%-8ld ", _L_gettime())@@
  114. #else
  115.  
  116. #define _DL_SHOWTIME(h,p) /* nothing */
  117.  
  118. #endif /* DL_SHOWTIME */
  119.  
  120. /*
  121.  * DLGHP(g,h,p,f...) - print a log message.
  122.  *
  123.  *     g - the guard; print the message iff this is true
  124.  *     h - the handler function that does the actual printing
  125.  *     p - a parameter for the handler function; e.g. a file descriptor.
  126.  *     f - the format and the data...
  127.  */
  128.  
  129. #if DL_LEVEL == 2 /* always log the message */
  130. #ifdef _NANA_FILTER_
  131. #define DLGHP(g,h,p,f...) \
  132.     do { \
  133.           @@break @__FILE__:__LINE__@@ \
  134.           @@command $bpnum@@ \
  135.           @@silent@@ \
  136.             _DL_SHOWTIME(h,p); \
  137.                   DL_DEFAULT_HANDLER(g,h,p,##f); \
  138.           @@cont@@ \
  139.           @@end@@ \
  140.     } while(0)
  141. #else
  142. #define DLGHP(g,h,p,f...) DL_MAKE_VALID_BREAKPOINT()
  143. #endif
  144.  
  145. #elif DL_LEVEL == 1 /* log it iff the guard is true */
  146.  
  147. #ifdef _NANA_FILTER_
  148. #define DLGHP(g,h,p,f...) \
  149.     do { \
  150.           if(g) { \
  151.                    @@break @__FILE__:__LINE__@@ \
  152.                    @@condition $bpnum g@@ \
  153.                    @@command $bpnum@@ \
  154.                    @@silent@@ \
  155.                    _DL_SHOWTIME(h,p); \
  156.                    DL_DEFAULT_HANDLER(g,h,p,##f); \
  157.                    @@cont@@ \
  158.                    @@end@@ \
  159.           } \
  160.     } while(0)
  161. #else
  162. #define DLGHP(g,h,p,f...) DL_MAKE_VALID_BREAKPOINT()
  163. #endif
  164.  
  165. #elif DL_LEVEL == 0 /* no logging so ignore them */
  166. #define DLGHP(g,h,p,f...) /* nothing */
  167. #endif /* DL_LEVEL */
  168.  
  169. /*
  170.  * And the user routines.
  171.  */
  172.  
  173. #define DL(f...) \
  174.           DLGHP(DL_DEFAULT_GUARD,DL_DEFAULT_HANDLER,DL_DEFAULT_PARAMS,##f)
  175. #define DLG(g,f...) \
  176.           DLGHP(g,DL_DEFAULT_HANDLER,DL_DEFAULT_PARAMS,##f)
  177. #define DLH(h,f...) \
  178.           DLGHP(DL_DEFAULT_GUARD,h,DL_DEFAULT_PARAMS,##f)
  179. #define DLP(p,f...) \
  180.           DLGHP(DL_DEFAULT_GUARD,DL_DEFAULT_HANDLER,p,##f)
  181. #define DLGP(g,p,f...) \
  182.           DLGHP(g,DL_DEFAULT_HANDLER,p,##f)
  183. #define DLHP(h,p,f...) \
  184.           DLGHP(DL_DEFAULT_GUARD,h,p,##f)
  185.  
  186.  
  187. /*
  188.  * V* - since the DL* macros take a variable numbers of arguments we
  189.  *    have problems compiling calls to L with C preprocessors other 
  190.  *    than GNU cccp. The V* macros are called using a bracketed arglist, e.g.
  191.  *    VDL((s,x,y))
  192.  *
  193.  *    if we are compiling with GNU C then they simply call the normal
  194.  *    varargs macros. if we are not using GNU C then they map to empty.
  195.  */
  196.  
  197. #define VDL(a) DL a
  198. #define VDLG(a) DLG a
  199. #define VDLH(a) DLH a
  200. #define VDLP(a) DLP a
  201. #define VDLGP(a) DLGP a
  202. #define VDLHP(a) DLHP a
  203. #define VDLGHP(a) DLGHP a
  204.  
  205. #else /* defined(WITHOUT_NANA) */
  206.  
  207. #define VDL(a) /* empty */
  208. #define VDLG(a) /* empty */
  209. #define VDLH(a) /* empty */
  210. #define VDLP(a) /* empty */
  211. #define VDLGP(a) /* empty */
  212. #define VDLHP(a) /* empty */
  213. #define VDLGHP(a) /* empty */
  214.  
  215. #endif /* !defined(WITHOUT_NANA) */
  216.  
  217.  
  218. #ifdef __cplusplus
  219. }
  220. #endif
  221.     
  222. #endif /* _DL_h_ */
  223.  
  224.  
  225.  
  226.  
  227.  
  228.